package com.offer;

import com.bean.ListNode;

/**
 * @Author: huangzhigao
 * @Date: 2023/3/4 17:23
 */
public class offer18 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode dummy = new ListNode();
        dummy.next = head;
        ListNode pre = dummy;
        ListNode cur = head;
        while (cur != null) {
            if (cur.val == val) {
                break;
            }
            pre = cur;
            cur = cur.next;

        }
        pre.next = cur.next;
        cur = null;
        return dummy.next;

    }
}
